package Jets.ui
{
   import Jets.ui.inface.IIcon;
   
   import flash.display.Bitmap;
   import flash.display.BitmapData;
   import flash.display.DisplayObjectContainer;
   import flash.events.Event;
   import flash.events.MouseEvent;
   import flash.utils.getTimer;
   import Jets.display.JContainer;
   
   public class JIcon extends JContainer implements IIcon
   {
      protected var _icon:String;
	  protected var bitmap:Bitmap;
	  private var _autoSzie:Boolean = false;
	  
      public function JIcon(parent:DisplayObjectContainer=null, cx:Number=0, cy:Number=0, url:String="") 
	  {
         addEventListener(MouseEvent.CLICK,this.doclick,false,int.MAX_VALUE);
         super(parent,cx,cy);
         this.icon = url;
      }
      
	  /**点击间隔时间*/
	  private var _InvalidTime:Number = 0;
      public function get InvalidTime() : uint 
	  {
         return this._InvalidTime;
	  }
	  
      public function set InvalidTime(value:uint) : void 
	  {
         if(this._InvalidTime != value)
         {
            this._InvalidTime = value;
         }
      }
      
	  /**判断是否在点击间隔时间内*/
      private var __canClickTime:int = 0;
      private function doclick(event:MouseEvent) : void 
	  {
         if(getTimer() > this.__canClickTime)
         {
            this.__canClickTime = getTimer() + this._InvalidTime;
         }
         else
         {
            event.stopImmediatePropagation();
         }
      }
      

      public function get autoSzie() : Boolean 
	  {
         return this._autoSzie;
      }
      public function set autoSzie(bool:Boolean) : void 
	  {
         this._autoSzie = bool;
         if(this._autoSzie == true)
         {
            if(this.bitmap.bitmapData)
            {
               this.setSize(this.bitmap.width,this.bitmap.height);
            }
            else
            {
               this.setSize(0,0);
            }
         }
      }
      
      override protected function init() : void 
	  {
         super.init();
         this.setSize(12,12);
         this.mouseChildren = false;
         this.doubleClickEnabled = true;
      }
      
      override protected function addChildren() : void 
	  {
         this.bitmap = new Bitmap();
         this.addChild(this.bitmap);
      }
      
      public function get icon() : String 
	  {
         return this._icon;
      }
      public function set icon(url:String) : void 
	  {
         if(url != this._icon)
         {

         }
      }
      
      protected function onadd(event:Event) : void 
	  {
         this.removeEventListener(Event.ADDED_TO_STAGE,this.onadd);
         if((this._icon) && this._icon.length > 0)
         {
            
         }
      }
      
      override public function get data() : Object 
	  {
         return this._icon;
      }
      override public function set data(value:Object) : void 
	  {
         this.icon = value as String;
         invalidate();
      }
      
      
      
      public function set bmpd(bit:BitmapData) : void 
	  {
         this.bitmap.bitmapData = bit;
         if(this.autoSzie)
         {
            if(this.bitmap.bitmapData)
            {
               this.setSize(this.bitmap.width,this.bitmap.height);
            }
            else
            {
               this.setSize(0,0);
            }
         }
      }
   }
}
